﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using Pantry.Entity;
using Pantry.DataAccess;


namespace Pantry.UnitTest
{


    [TestFixture]
    public class TestContactDao
    {

        private ContactDao _contactDao;
        private Contact _nullContact;
        private Contact _validContact;
        private Contact _invalidContact;
        private const string ConnectionString = "Server=10.16.102.126;Database=Pantry_MockProject;Integrated Security=True;";

        [SetUp]
        public void Init()
        {
            _contactDao = new ContactDao(ConnectionString); 
            _nullContact = new Contact();
            _validContact = new Contact
                {
                    ContactId = 1,
                    FirstName = "Dai Quang",
                    Surname = "Nguyen",
                    KnownAs = "Map ngao ngo",
                    OfficePhone = "098888869669",
                    MobilePhone = "098888869669",
                    HomePhone = "098888869669",
                    Email = "quangnd6@fsoft.com.vn",
                    ManagerId = 1,
                    ContactType = 1,
                    BestContactMethod = 1,
                    JobRole = "Culi",
                    WorkBase = "FSU Mat Trang",
                    JobTitle = "Culi hang hieu"
                };
           _invalidContact = new Contact
                {
                    //ContactId = 1,
                    FirstName = "Dai Quang",
                    Surname = "Nguyen",
                    KnownAs = "Map ngao ngo",
                    OfficePhone = "098888869669",
                    MobilePhone = "098888869669",
                    HomePhone = "098888869669",
                    Email = "quangnd6@fsoft.com.vn",
                    ManagerId = 1,
                    ContactType = 1,
                    BestContactMethod = 1,
                    JobRole = "Culi",
                    WorkBase = "FSU Mat Trang",
                    JobTitle = "Culi hang hieu"
                };
        }

        [Test]
        public void CreateNewUserNullObject()
        {
            int result = _contactDao.CreateNewContact(_nullContact);
            Assert.AreEqual(result, 0);
        }
        [Test]
        public void CreateNewUserInvalidObject()
        {
            int result = _contactDao.CreateNewContact(_invalidContact);
            Assert.AreEqual(result, 0);
        }
        [Test]
        public void CreateNewUserValidObject()
        {
            int result = _contactDao.CreateNewContact(_validContact);
            Assert.AreEqual(result, 1);
        }

        //Test method UpdateContact
        [Test]
        public void UpdateContact_NullObject()
        {
            int result = _contactDao.UpdateContact(_nullContact);
            Assert.AreEqual(result, 0);
        }
        [Test] 
        public void UpdateContact_InvalidObject()
        {
            int result = _contactDao.UpdateContact(_invalidContact);
            Assert.AreEqual(result, 0);
        }
        [Test]
        public void UpdateContact_ValidObject()
        {
            int result = _contactDao.UpdateContact(_validContact);
            Assert.AreEqual(result, 1);
        }
    }
}
